<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

function wait(ms) {
  return new Promise(resolve => step_timeout(resolve, ms));
}

promise_test(async () => {
  const req = new Request('/', {method: 'POST', body: 'hello'});
  await wait(10);
  gc();
  // TODO(yhirano): Use .body here once it has been exposed.
  const text = await req.text()
  assert_equals(text, 'hello');
}, 'request.body should be kept');

promise_test(async () => {
  const expected = [1, 8, 2, 4, 5];
  const res = new Response(new Uint8Array(expected));
  await wait(10);
  gc();
  assert_false(res.bodyUsed);
  const decoder = new TextDecoder();
  let actual = [];
  const reader = res.body.getReader();
  while (true) {
    const v = await reader.read();
    if (v.done) {
      break;
    }
    actual = actual.concat(Array.from(v.value))
  }
  assert_array_equals(actual, expected);
}, 'response.body should be kept');

</script>
